﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// 唤醒广告
public class AwakeAds : TJLogger {

	private AndroidJavaObject jo = null;

	public void Init (string timeStr)
	{
		int time = 20;
		try{
			time = int.Parse(timeStr);
		}catch(System.Exception e){
			TJLogError ("设置唤醒时间有误：" + e.Message);
		}
		TJLog ("唤醒提示初始化，时间：" + time);
		if (jo == null) {
			jo = new AndroidJavaObject ("com.tjutil.Awake");
			jo.Call ("setCallBack", "TJSDK", "OnAwakeResult");

			jo.Call ("startAwake",time);
		}
	}

	public void SetTime(int time){
		if(jo != null){
			TJLog ("设置唤醒时间：" + time);
			jo.Call ("setTime",time);
		}
	}

	public void Stop(){
		if(jo != null){
			TJLog ("停止唤醒提示");
			jo.Call ("stopAwake");
		}
	}
	
	public void OnAwakeResult (string result)
	{
		TJLog ("唤醒提示回调：" + result);
		string[] param = result.Split ('|');
		switch (param[0]) {
		case "on":			
			Debug.Log ("可以打开唤醒广告");
			TJSDK.Instance.ShowSplash ();
			break;
		case "off": 		
			Debug.Log("时间不足，不用打开唤醒广告"); 	
			break;
		default: 			
			Debug.Log("未知状态");					
			break;
		}
		TJLog ("已在后台运行：" + param [1] + " 秒");
	}
}
